package Exception;

public class Test1 {
}
class LogIn {
  private String userName = "admin";
  private String password = "123456";

  public void loginInfo(String userName, String password) /*throws UseNameException,PasswordException*/{//在这里声明了你可能抛出了的异常
   if (!this.userName.equals(userName)) {
    /*System.out.println("用户名有误！");*///不用这个打印了直接抛出了一个自定义异常
    throw new UseNameException("用户名有误！");
   }if (!this.password.equals(password)) {
    /*System.out.println("密码有误！");*/
    throw new PasswordException("密码有误！");
   }System.out.println("登陆成功");
   //这个时候我们也可以自定义异常来实现这种方法
  }

  public static void main(String[] args) {
   LogIn logIn = new LogIn();
   try{
       logIn.loginInfo("admin1", "123456");
   }catch (UseNameException e){
       e.printStackTrace();
       System.out.println("UseNameException");
   }catch (PasswordException e){
       e.printStackTrace();
       System.out.println("PasswordException");
   }
  }
}
